package com.ruoyi.system.task;

import com.ruoyi.system.domain.BdmCloudInventoryItem;
import com.ruoyi.system.domain.BdmUser;
import com.ruoyi.system.enums.BdmCloudInventoryEnum;
import com.ruoyi.system.service.IBdmCloudInventoryItemService;
import com.ruoyi.system.service.IBdmCloudInventoryService;
import com.ruoyi.system.service.IBdmUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("cloudInventoryTask")
@Slf4j
public class CloudInventoryTask {

    @Autowired
    private IBdmCloudInventoryService bdmCloudInventoryService;

    @Autowired
    private IBdmCloudInventoryItemService bdmCloudInventoryItemService;

    @Autowired
    private IBdmUserService bdmUserService;

   //提醒上级 进货 或者 商城进货
    public void  cloudStockShipments(){
        log.info("云库存提醒上级定时任务执行了");
        //查询出进货中的 云库存明细
        List<BdmCloudInventoryItem> bdmCloudInventoryItems = bdmCloudInventoryItemService.lambdaQuery().eq(BdmCloudInventoryItem::getStockType, BdmCloudInventoryEnum.IN_STOCK.getType()).list();
        for (BdmCloudInventoryItem bdmCloudInventoryItem : bdmCloudInventoryItems) {
            //查询用户信息
            BdmUser bdmUser = bdmUserService.lambdaQuery().eq(BdmUser::getSysUserid, bdmCloudInventoryItem.getUserId()).one();
            //添加修改云库存明细

            bdmCloudInventoryService.addBdmCloudInventoryItem(bdmCloudInventoryItem, bdmUser);
        }
    }

}
